package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.DaoPledgeDirectPush;
import com.sc.nft.mapper.DaoPledgeDirectPushMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.Objects;

/**
 * dao质押活动直推记录表(sc_dao_pledge_direct_push)数据DAO
 *
 * @author jinpinhai
 * @description Generator
 * @since 2024-11-28 10:30:11
 */
@Slf4j
@Repository
public class DaoPledgeDirectPushDao extends ServiceImpl<DaoPledgeDirectPushMapper, DaoPledgeDirectPush> {

    public IPage<DaoPledgeDirectPush> page(Page page, Long daoId, Long targetUserId, Long sourceUserId) {
        LambdaQueryWrapper<DaoPledgeDirectPush> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DaoPledgeDirectPush::getDaoId, daoId);
        wrapper.eq(Objects.nonNull(targetUserId), DaoPledgeDirectPush::getTargetUserId, targetUserId);
        wrapper.eq(Objects.nonNull(sourceUserId), DaoPledgeDirectPush::getSourceUserId, sourceUserId);
        wrapper.orderByDesc(DaoPledgeDirectPush::getGrantTime);
        return page(page, wrapper);
    }
}